import React from "react";
import { pageIndex, pages } from "./common/routerConfig";
import {
  HashRouter as Router,
  Route,
  Switch,
  Redirect,
} from "react-router-dom";
import AuthRoute from "./components/authRoute/index";
import { createHashHistory } from "history";

// 总的父组件，掌控所有路由
const Index = () => {
  return (
    <Router history={createHashHistory()}>
      <Switch>
        {pages.map((route, i) =>
          route.name === "login" ? (
            <Route path={route.path} component={route.page} />
          ) : (
            <AuthRoute path={route.path} component={route.page} />
          )
        )}
        <Redirect to={pages[pageIndex.login].path} />
      </Switch>
    </Router>
  );
};

export default Index;
